package com.huazi.www.doctor.doctorg.service.impl;


import com.huazi.util.SessionUtil;
import com.huazi.www.doctor.doctorg.dao.QueueDao;
import com.huazi.www.doctor.doctorg.entity.QueueEntity;
import com.huazi.www.doctor.doctorg.service.QueueService;
import com.huazi.www.doctor.doctorg.util.Page;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QueueServiceImpl implements QueueService {
    /**
     * 分页
     *
     * @param name
     * @param state
     * @param currentPage
     * @return
     */

    SqlSession session = SessionUtil.getSession();
    QueueDao mapper = session.getMapper(QueueDao.class);
    @Override
    public Page<QueueEntity> page(int doctorid, String name, int state, int currentPage) {
        Map map=new HashMap();
        map.put("doctorid",doctorid);
        map.put("name",name);
        map.put("state",state);
        //new对象
        Page<QueueEntity> page = new Page<>();
//        //写入当前页数
        page.setCurrPageNo(currentPage);
//        //设置每页显示数量
        page.setPageSize(20);
//        //写入总记录数
        page.setTotalCount(mapper.getcount(map));
//        //计算出初始位置
        int start = (currentPage - 1) * page.getPageSize();
//
        map.put("start",start);
        map.put("page",page.getPageSize());
        List<QueueEntity> listselect = mapper.listselect(map);
//        List<QueueEntity> list = queue.list(doctorid, name, state, start, page.getPageSize());
        page.setNewsList(listselect);
        session.close();
        return page;
    }

    //状态修改
    public void stateUpdate(int id) {
    mapper.stateUpdate(id);
    session.commit();
    session.close();
    }

}
